package com.lemner.ke.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemner.ke.R;
import com.lemner.ke.base.BaseActivity;
import com.lemner.ke.base.BaseListener;
import com.lemner.ke.base.BaseObjectBean;
import com.lemner.ke.base.TopBar;
import com.lemner.ke.base.URL;
import com.lemner.ke.bean.UserBean;
import com.lemner.ke.model.persional.GetUserByIdsModel;
import com.lemner.ke.util.LoadImageUtils;

import de.hdodenhof.circleimageview.CircleImageView;

public class MineActivity extends BaseActivity {
    private LinearLayout ll_setting,ll_edit,ll_collect,ll_browse_history,ll_feedback;
    private CircleImageView civ_head;
    private ImageView iv_sex;
    private TextView tv_name,tv_age;

    private String ids;
    @Override
    public int getLayoutFile() {
        return R.layout.activity_mine;
    }

    @Override
    public void initView() {
        topBar.setTitle("我的");
        ll_setting=findViewById(R.id.ll_mine_setting);
        ll_edit=findViewById(R.id.ll_mine_edit);
        civ_head=findViewById(R.id.civ_mine_head);
        tv_name=findViewById(R.id.tv_mine_name);
        iv_sex=findViewById(R.id.iv_mine_sex);
        tv_age=findViewById(R.id.tv_mine_age);
        ll_collect=findViewById(R.id.ll_mine_collect);
        ll_browse_history=findViewById(R.id.ll_mine__browse_history);
        ll_feedback=findViewById(R.id.ll_mine_feedback);
    }

    @Override
    public void initEvent() {
        ll_setting.setOnClickListener(this);
        ll_edit.setOnClickListener(this);
        tv_name.setOnClickListener(this);
        ll_collect.setOnClickListener(this);
        ll_browse_history.setOnClickListener(this);
        ll_feedback.setOnClickListener(this);
    }

    @Override
    public void initData() {
        if (intent != null) {
            ids = intent.getStringExtra("ids");
        }
        updateData();
    }

    @Override
    protected void initSetting() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.ll_mine_setting:
                startActivity(SettingActivity.class);
                break;
            case R.id.ll_mine_edit:
                startActivity(PersonalActivity.class);
                break;
            case R.id.ll_mine_collect:
                Bundle bundle1=new Bundle();
                bundle1.putInt("page",0);
                startActivity(MyCollectionActivity.class, bundle1);
                break;
            case R.id.ll_mine__browse_history:
                Bundle bundle2=new Bundle();
                bundle2.putInt("page",1);
                startActivity(MyCollectionActivity.class, bundle2);
                break;
            case R.id.ll_mine_feedback:
                startActivity(FeedbackActivity.class);
                break;
        }
    }
    public void updateData() {
        new GetUserByIdsModel().getUserByIds(ids, new BaseListener() {
            @Override
            public void onResponse(Object o) {
                UserBean userBean = ((BaseObjectBean<UserBean>) o).getData();
                if (null != userBean.getHeadcovers()) {
                    String url = URL.BASE_URL + userBean.getHeadcovers();
                    LoadImageUtils.loadImage(url, civ_head);
                } else {
                    civ_head.setImageResource(R.drawable.background_ee);
                }

                if (userBean.getAge() != 0) {
                    tv_age.setText(userBean.getAge() + "岁");
                }

                tv_name.setText(userBean.getNames());

                if (userBean.getGender() == 2) {

                } else if (userBean.getGender() == 1) {
                    iv_sex.setImageResource(R.drawable.man);
                } else {
                    iv_sex.setImageResource(R.drawable.woman);
                }
            }

            @Override
            public void onFail(String msg) {

            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        updateData();
    }
}
